package com.emmy.walnut.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.emmy.walnut.R;
import com.emmy.walnut.model.Label;

import java.util.ArrayList;
import java.util.List;

public class ActivityAdapter extends RecyclerView.Adapter<ActivityAdapter.MyViewHolder>{

    private List<Label> mList = new ArrayList<>();
    private Context mContext;
    private OnItemClickListener mOnItemClickListener;
    public ActivityAdapter(Context mContext, List<Label> mList){
        this.mContext = mContext;
        if (mList!=null){
            this.mList = mList;
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(mContext).
                inflate(R.layout.item_activity, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.textView.setText(mList.get(position).getLabelName());
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView textView;
        MyViewHolder(View view){
            super(view);
            textView = view.findViewById(R.id.activity_item);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mOnItemClickListener!=null){
                        mOnItemClickListener.onItemClick(v, getAdapterPosition());
                    }
                }
            });
        }
    }

    public interface OnItemClickListener{
        void onItemClick(View view, int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        mOnItemClickListener = onItemClickListener;
    }
}
